package org.example;

import com.alibaba.fastjson.JSON;
import com.entity.TbClass;
import com.mapper.TbClassMapper;
import com.util.ResponseUtil;
import com.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "tbCacheOne", value = "/cache/testOne")
public class TestCacheOneServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        String code = request.getParameter("code");
        String majorCode = request.getParameter("majorCode");


        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        TbClassMapper tbClassMapper = sqlSession.getMapper(TbClassMapper.class);

        // 查询班级
        Map<String, String> param = new HashMap<String, String>();
        param.put("classCode", code);
        TbClass tbClass = tbClassMapper.selectTbClassByCode(param);
        System.out.println(JSON.toJSONString(tbClass));
        System.out.println("---------暂停中--------");

        // 重新查询班级
        TbClass tbClass2 = tbClassMapper.selectTbClassByCode(param);
        System.out.println(JSON.toJSONString(tbClass2));

        ResponseUtil.doPrint(response, JSON.toJSONString(JSON.toJSONString(tbClass2)));
    }

    public void destroy() {
    }
}